<?php

class File_Info_Model extends Model
{
	public function __construct()
	{
		parent::Model();
		$this->name="";
		$this->caption="";
		
		// open the database
		$this->load->database();
	}

	function add_record($filename, $itemId)
	{
		$sql = "INSERT INTO file_info (filename, item_id)
				VALUES (".$this->db->escape($filename).", ".$this->db->escape($itemId).")";

		$this->db->query($sql);
		
	}

	function delete($id)
	{
		$this->db->query('DELETE FROM file_info 
									WHERE image_id = \''.$id.'\'');
		
	//	echo "Image has been deleted successfully!";
	}

	function edit_caption($id, $newcaption)
	{
		$data = array(
               'caption' => $newcaption,
            );

		$this->db->update('file_info', $data,  array('image_id' => $id)); 
	}
	
	function get_file_information($cat)
	{
		echo "category entered is :".$cat."<br />\n";
		$result = $this->db->query('SELECT item_id, filename, category, caption
									FROM file_info 
									WHERE category = \''.$cat.'\'');

		return $result->result();
	}
		
	function get_item_images($itemID)
	{
		$result = $this->db->query('SELECT image_id, filename, category, caption, item_id
									FROM file_info 
									WHERE item_id = \''.$itemID.'\'');
		
		return $result->result();
	}

}
?>